﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NppPluginNET;
using NppPluginNET.Speech;
using System.Text.RegularExpressions;

namespace SpeechTest
{
    class Program
    {

      private static string FindClassName(string text)
      {
        //string text = NPPPlugin.GetCurrentDocumentText();
        string className = "";

        Match m = Regex.Match(text,@"public\s+class\s+(\w+)");
        if (m.Success)
          className = m.Groups[1].Value;

        return className;

      }

      private static Dictionary<string, string> FindMembers(string text)
      {
        //string text = NPPPlugin.GetCurrentDocumentText();
        Dictionary<string, string> members = new Dictionary<string, string>();

        MatchCollection matches = Regex.Matches(text,@"(private|protected)\s+(\w+)\s+(\w+)\s*;");
        foreach (Match m in matches)
        {
          if (m.Success)
          {
            members.Add(m.Groups[3].Value, m.Groups[2].Value);
          }
        }

        return members;
      }

      public static string testString = @"using System.Text.RegularExpressions;

namespace SpeechTest
{
    public  class  Program
    {
      private string  firstName;
      private string lastName ;
      private int count;

      private static string FindClassName()
      {
      ";

        static void Main(string[] args)
        {
            //Console.WriteLine("---- Start");
            //SpeechManager speechManager = new SpeechManager();
            //speechManager.Initialize();
            //Console.WriteLine("initzialized..");
            ////speechManager = new SpeechManager();
            //speechManager.CodeGenerationRecognized += CodeGenerationRecognized;
            //speechManager.EditorNavigationRecognized += EditorNavigationRecognized;
            //speechManager.TextManipulationRecognized += TextManipulationRecognized;
            //while (true)
            //{
            //}
            //////Console.ReadKey();
            //String s = "test \\n \\n test";
            //Console.WriteLine(Regex.Unescape(s));


          string className = FindClassName(testString);
          FindMembers(testString);

        }

        private static string UnespaceString(string s)
        {
            return s.Replace("\\", @"\");
        }


        static void EditorNavigationRecognized(object sender, EditorControlEventArgs e)
        {
            Console.WriteLine("--EditorNavigation--");
            Console.WriteLine(e.EditorControl);
            Console.WriteLine(e.ControlScope);
            Console.WriteLine(e.Number);
            Console.WriteLine("-------------------");
        }

        static void TextManipulationRecognized(object sender, EditorControlEventArgs e)
        {
            Console.WriteLine("--TextManipulation--");
            Console.WriteLine(e.EditorControl);
            Console.WriteLine(e.ControlScope);
            Console.WriteLine(e.Number);
            Console.WriteLine("-------------------");
        }

        static void CodeGenerationRecognized(object sender, CodeGenerationEventArgs e)
        {
            Console.WriteLine(e.ParseResult.Text);
        }

    }
}
